#include <Game/GameStartState.h>
#include <Game/GameExitState.h>
#include <MainWindow.h>

namespace pp
{
    const ne::real GameStartState::START_TIME = 2.0f;

    GameStartState::GameStartState(Game *pContent)
        : GameState(pContent, GAME_START_STATE_ID),
          mTimer(0)
    {
    }

    void GameStartState::onReset()
    {
        mTimer = 0;
    }

    uint32_t GameStartState::onEvent(GameEvent &event)
    {
        uint32_t id = GameState::onEvent(event);
        if (id == mID)
        {
            if (event.ID == GAME_EXIT_EVENT_ID)
            {
                if (mTimer >= START_TIME)
                {
                    return GAME_EXIT_STATE_ID;
                }
            }
        }
        return id;
    }

    uint32_t GameStartState::onTick(const ne::real interval)
    {
        mTimer += interval;
        if (mTimer < 1.0f)
        {
            mpContent->getMainWindow()->setBackgroundColor(
                ne::Color::Lerp(ne::Color::BLACK,
                                ne::Color::WHITE,
                                mTimer));
        }
        else if (mTimer < 2.0f)
        {
            mpContent->getMainWindow()->setBackgroundColor(
                ne::Color::Lerp(ne::Color::WHITE,
                                ne::Color::DARK,
                                mTimer - 1.0f));
        }
        else
        {
            mpContent->getMainWindow()->setBackgroundColor(ne::Color::DARK);
        }

        return mID;
    }

    GameStartState::~GameStartState()
    {
    }
}
